<template>
  <div>
    <van-cell title="搜索历史">
      <van-icon slot="right-icon" name="delete-o" class="icon" v-show="!isDelete" @click="isDelete=!isDelete"></van-icon>
      <div slot="extra" v-show="isDelete">
        <span class="span" @click="removeAll">全部删除</span>
        <span class="span" @click="isDelete=!isDelete">完成</span>
      </div>
    </van-cell>
    <van-cell :title="searchHistorie" v-for="(searchHistorie,index) in searchHistories" :key="index" @click="deleteHistory(searchHistorie,index)">
      <van-icon :name="isDelete?'close':''"></van-icon>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "History",
  created() {},
  data() {
    return {
      isDelete: false
    };
  },
  props: {
    searchHistories:{
      type:Array
    }
  },
  methods: {
    deleteHistory(searchHistorie,index){
      // console.log(1);
      if(this.isDelete){
        // 删除状态  直接删
      this.searchHistories.splice(index,1)
      }else{
        // 删除状态  去搜索  把历史内容 放到搜索框中
        this.$bus.$emit('search',searchHistorie)
        // console.log(searchHistorie);
      }
    },
    removeAll(){
      this.$emit('updata-History',[])
    }
  },
};
</script>

<style lang="less" scoped>
  .span{
    font-size: 13px;
    color: #969799;
    margin-left: 5px;
  }
.icon{
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
